import axios from '@/libs/api.request'

/**
 * addResource（新增资源)
 * @param {string} resName 必填 资源名称
 * @param {1 | 2} resType 必填 资源类型 1-菜单，2-按钮
 * @param {string} resUrls 必填 资源连接
 * @param {number} sort 序号
 * @param {number} isPub 是否公开
 * @param {file} file 资源图片
 * @param {number} isParent
 * @example .
 * addResource({"resourceName":"用户管理","resourceType":"1","url":"urltestchild","seq":"1","parentId":""})
 */
export const addResource = ({
  //   必填参数：resourceName:资源名称,
  // 必填参数：url：资源URL
  // 必填参数：seq：顺序
  // 必填参数：resourceType：资源类型（1-菜单，2-按钮）
  note,
  params,
  resParentId,
  pubFlag,
  resIcon,
  resName,
  resType,
  resUrls,
  resCode,
  sort,
  applicationType,
  menuType
}) => {
  return axios.request({
    url: '/gas/domain/resource/add',
    data: {
      note,
      params,
      resParentId,
      pubFlag,
      resIcon,
      resName,
      resType,
      resUrls,
      resCode,
      sort,
      applicationType,
      menuType
    },
    method: 'post'
  })
}
/**
 * updateResource（更新资源
 * @param {*} param0
 */
export const updateResource = ({
  note,
  params,
  resParentId,
  resourceId,
  resName,
  resType,
  resUrls,
  sort,
  pubFlag,
  resIcon,
  resCode,
  status,
  applicationType,
  menuType
}) => {
  return axios.request({
    url: '/gas/domain/resource/update',
    data: {
      note,
      params,
      resCode,
      resParentId,
      resourceId,
      resName,
      resType,
      resUrls,
      sort,
      pubFlag,
      resIcon,
      status,
      applicationType,
      menuType
    },
    method: 'post'
  })
}
/**
 * finResourceALlTree（所有资源树查询)
 * @param {string} resParentId 父资源ID
 * @param {string} status 状态（1、生效 2、禁用)
 * @param {1 | 2} resType 资源类型 1-菜单，2-按钮
 * @param {number} roleId 角色ID
 */
export const finResourceALlTree = ({
  resParentId,
  status,
  resType,
  roleId,
  finResourceTree,
  applicationType
}) => {
  return axios.request({
    url: '/gas/domain/resource/all/tree',
    data: {
      resParentId,
      status,
      resType,
      roleId,
      finResourceTree,
      applicationType
    },
    method: 'post'
  })
}
/**
 * 业务系统获取资源列表接口
 * @param {String} sessionId .
 */
export const bsGetResourceList = (sessionId) => {
  return axios.request({
    url: '/gas/domain/resource/bsGetResourceList',
    data: {
      sessionId
    },
    method: 'post'
  })
}
/**
 * deleteResource（删除资源)
 * @param {number} resId .
 */
export const deleteResource = (resourceId) => {
  return axios.request({
    url: '/gas/domain/resource/delete',
    data: {
      resourceId
    },
    method: 'post'
  })
}
/**
 * getResourceInfo（根据ID查询资源）
 * @param {number} resourceId 资源id
 */
export const getResourceInfo = (resourceId) => {
  return axios.request({
    url: '/gas/domain/resource/getResourceInfo',
    data: {
      resourceId
    },
    method: 'post'
  })
}
/**
 * listResourcePage查询资源
 * @param {number} resourceId 资源id
 */
export const listResourcePage = ({
  resParentId,
  pageSize,
  pageNum,
  resType,
  applicationType
}) => {
  return axios.request({
    url: '/gas/domain/resource/list',
    data: {
      resParentId,
      pageSize,
      pageNum,
      resType,
      applicationType
    },
    method: 'post'
  })
}
/**
 * finResourceMenuTree（查询资源-登录后菜单展示
 * @param {number} resourceId 资源id
 */
export const finResourceMenuTree = (resCode) => {
  return axios.request({
    url: '/gas/domain/resource/menu/tree',
    data: {
      resCode
    },
    method: 'post'
  })
}
/**
 * queryDomainResource（查询该域拥有的资源，和该域未拥有的资源 addedResources、toAddResoures 双向绑定树用的接口）
 * @param {*} resourceId
 */
export const queryDomainResource = ({
  domainId,
  applicationType
}) => {
  return axios.request({
    url: '/gas/domain/resource/queryDomainResource',
    data: {
      domainId,
      applicationType
    },
    method: 'post'
  })
}
/**
 * 角色资源树（默认选中当前角色已有的资源）
 * @param {*} param0
 */
export const queryRoleResourceTree = ({
  roleId,
  roleParentId,
  applicationType,
  cleanCheck
}) => {
  return axios.request({
    url: '/gas/domain/resource/queryRoleResourceTree',
    data: {
      roleId,
      roleParentId,
      applicationType,
      cleanCheck
    },
    method: 'post'
  })
}
/* 个性化配置列表接口 */
export const getPersonalizationResourceList = ({ resName, pageSize, pageNum, resParentId, applicationType }
) => {
  return axios.request({
    url: '/gas/domain/resource/getPersonalizationResourceList',
    data: {
      resName, pageSize, pageNum, resParentId, applicationType
    },
    method: 'post'
  })
}
/* 个性化编辑保存接口 */
export const savePersonalizationResource = ({
  note,
  resName,
  // url,
  showFlag,
  resIcon,
  domainResId,
  resourceId,
  sort
}) => {
  return axios.request({
    url: '/gas/domain/resource/savePersonalizationResource',
    data: {
      note,
      resName,
      // url,
      showFlag,
      resIcon,
      domainResId,
      resourceId,
      sort
    },
    method: 'post'
  })
}
/* 重置数据 (个性化编辑重置接口) */
export const resetPersonalizationResource = (
  domainResId
) => {
  return axios.request({
    url: '/gas/domain/resource/resetPersonalizationResource',
    data: {
      domainResId
    },
    method: 'post'
  })
}
/*  根据菜单ID获取button资源接口 */
export const getButtonsByMenuId = (resourceId) => {
  return axios.request({
    url: '/gas/domain/resource/getButtonsByMenuId',
    data: {
      resourceId
    },
    method: 'post'
  })
}
/*  个性化设置的树 personalResourcetree */
export const personalResourcetree = (applicationType) => {
  return axios.request({
    url: '/gas/domain/resource/personalResourcetree',
    data: {
      applicationType
    },
    method: 'post'
  })
}
